<?php
$this->breadcrumbs=array(
	'Content Types'=>array('index'),
	'Manage',
);

$this->menu=array(
//	array('label'=>'Create ContentType', 'url'=>array('create')),
);

Yii::app()->clientScript->registerScript('search', "
$('.search-button').click(function(){
    $('.search-form').toggle();
    return false;
});
$('.search-form form').submit(function(){
    $.fn.yiiGridView.update('content-type-grid', {
        data: $(this).serialize()
    });
    return false;
});
");

if(Yii::app()->request->enableCsrfValidation)
{
    $csrfTokenName = Yii::app()->request->csrfTokenName;
    $csrfToken = Yii::app()->request->csrfToken;
    $csrf = "\n\t\tdata:{ '$csrfTokenName':'$csrfToken' },";
}
else
    $csrf = '';
Yii::app()->clientScript->registerScript('change-status', "
jQuery('#content-type-grid .status-column a').live('click',function() {
    $.fn.yiiGridView.update('content-type-grid', {
        type:'POST',
        url:$(this).attr('href'),$csrf
        success:function(data) {
            $.fn.yiiGridView.update('content-type-grid');
        },
        error:function(XHR) {
        }
    });
    return false;
}); 
");
?>

<h1>Manage Content Types</h1>

<!--
<?php //echo CHtml::link('Advanced Search','#',array('class'=>'search-button')); ?>
<div class="search-form" style="display:none">
<?php //$this->renderPartial('_search',array('model'=>$model,)); ?>
</div>
-->

<?php $grid = $this->widget('zii.widgets.grid.CGridView', array(
	'id'=>'content-type-grid',
	'dataProvider'=>$model->search(),
	'filter'=>$model,
//    'selectableRows'=>2,
	'columns'=>array(
        /*array(
            'class'=>'CCheckBoxColumn',
            'value'=>'$data->id',
            'htmlOptions'=>array('width'=>'3%'),
        ),*/
		'name',
        array(
            'name'=>'description',
            'value'=>'$data->description',
            'sortable'=>false,
        ),
        array(
            'name'=>'model',
            'value'=>'$data->model',
            'sortable'=>false,
        ),
        array(
            'name'=>'creation_datetime',
            'value'=>'$data->creation_datetime',
            'filter'=>false,
        ),
        array(
            'name'=>'last_update',
            'value'=>'$data->last_update',
            'filter'=>false,
        ),
        array(
            'name'=>'id',
            'value'=>'$data->id',
            'htmlOptions'=>array('width'=>'3%','align'=>'center'),
        ),
        array(
            'name'=>'status',
            'type'=>'raw',
            'value'=>'CHtml::link("Change Status", array("/Core/service/ajax", "SID"=>"Cms.contentType.changeStatus", "ids[]"=>$data->id, "value"=>$data->status ? 0 : 1), array("class"=>($data->status ? "active" : "")))',
            'filter'=>false,
            'sortable'=>false,
            'htmlOptions'=>array(
                'class'=>'status-column'
            )
        ),
		array(
			'class'=>'CButtonColumn',
            'template'=>'{update} {delete}',
            'updateButtonUrl'=>'is_object($data->form) ? Yii::app()->controller->createUrl("/Cms/admin/widget/editForm",array("id"=>$data->form->id)) : Yii::app()->controller->createUrl("update",array("id"=>$data->primaryKey))',
		),
	),
)); 

if ($grid->dataProvider->ItemCount) {
    $this->menu[] = array('label' => 'Delete selected items', 'url'=>$this->createUrl('delete'), 'linkOptions' => array('onclick'=>'return multipleDelete("content-type-grid",this.href)'));
}
Yii::app()->clientScript->registerScriptFile(Yii::app()->core->AssetUrl.'/scripts/gridview.js', CClientScript::POS_BEGIN);
?>